﻿@model Dictionary<string, yq.WebModel.RoleLinkButton>
           @Url.TreeScript()
<script>

var setting = 
{
			data: {
				simpleData: {
					enable: true
				}
			},
            callback: {
			beforeClick: function(treeId, treeNode) {
				var zTree = $.fn.zTree.getZTreeObj("tree");
                 //当前值
				  currVal=treeNode.val;
			}
		   }
};
$(function()
{
  info();
});

function info()
{
 //请求回数据
 $.AjaxServer("@(Url.Action("DoSelectDep"))",{},function(data)
 {
    	$.fn.zTree.init($("#treeDemo"), setting, data);
 });
}
var currVal=null;
</script>
<div class="zTreeDemoBackground left">
    <ul id="treeDemo" class="ztree">
        加载中...
    </ul>
</div>
<div style="padding-top: 10px; text-align: right;">
    @Html.ActionRoleLink(Model["添加"], new { }, new { @class = "btn btn-warning", onclick = "return DepartmentEidtAndAdd(this)" })
    @Html.ActionRoleLink(Model["编辑"], new { }, new { @class = "btn btn-info", onclick = "return DepartmentEidtAndAdd(this)" })
    @Html.ActionRoleLink(Model["删除"], new { }, new { @class = "btn btn-danger", onclick = "return DepartmentDel(this)" })
</div>
<script>

    //选中
    function yesCurr()
    {
        if (currVal == null)
        {
            $.alert("请选中一个部门");
            return false;
        } else
        {
            return true;
        }
    }

    //编辑或者添加
    function DepartmentEidtAndAdd(obj)
    {
      if(yesCurr()==false)
      {
        return false;
      }

        try
        {
            var href = $(obj).attr("href");
            $.AjaxServer(href,{ DepartmentId:currVal }, function (data)
            {
                var id = newGuid();
                art.dialog({
                    title: "",
                    id: id,
                    fixed: false,
                    lock: false,
                    content: "<span style='line-height:22px;'>" + _SetDialogContent(data, id) + "</span>",
                    ok: false,
                    close: info
                });
                documentCheck();
            });
        }
        catch (e)
        {

        }
        return false;
    }


    //选中
    function DepartmentDel(obj)
    {
      if(yesCurr()==false)
      {
        return false;
      }
        try
        {
            var href = $(obj).attr("href");
            $.confim("确认删除？", function ()
            {
                $.AjaxServer(href, { DepartmentId:currVal }, function (data)
                {
                    if (data.Status == 1)
                    {
                       $.tips("操作成功");
                        info();

                    } else
                    {
                        $.tips(data.ErrorText);
                    }
                });
            });
        }
        catch (e)
        {

        }
        return false;
    }



</script>
